package com.smfx.yxt;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.smfx.yxt.model.TeacherInfo;
import com.smfx.yxt.service.ITeacherService;

public class TeacherPositionService extends BaseTest {
	
	@Autowired
	private ITeacherService teacherService;
	
	@Test
	public void updatePosition() {
		try {
			List<TeacherInfo> list = teacherService.selectList();
			for(TeacherInfo teacher : list) {
				if(StringUtils.isNotBlank(teacher.getIds())) {
					String[] array = teacher.getIds().split(",");
					String position = "";
					for (int i = 0; i < array.length; i++) {
						Integer v = vmap.get(Integer.valueOf(array[i]));
						if(v != null) {
							position += String.valueOf(v) + (i < array.length-1 ? "," : "");
						}
					}
					teacher.setPosition(position);
					teacherService.updateById(teacher);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}
	
	public static Map<Integer, Integer> vmap = getMap();
	public static Map<Integer, Integer> getMap() {
		if(vmap != null) return vmap;
		Map<Integer, Integer> map = new HashMap<>();
		map.put(1, 5);
		map.put(2, 1001);
		map.put(3, 2001);
		map.put(4, 2001);
		map.put(5, 2001);
		map.put(6, 5010);
		map.put(7, 3001);
		map.put(9, 6010);
		map.put(10, 3005);
		map.put(11, 3003);
		map.put(14, 3007);
		map.put(15, 6050);
		map.put(16, 3008);
		map.put(19, 3009);
		map.put(21, 7110);
		map.put(22, 5020);
		map.put(23, 3005);
		map.put(24, 7010);
		map.put(26, 6020);
		map.put(28, 6030);
		map.put(29, 3004);
		return map;
	}
}
